package cn.js.websocket;

import org.h2.tools.Server;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

public class Test {

    private static String driver = "org.h2.Driver"; // h2数据库驱动类
    private static String url = "jdbc:h2:./test2";  // cc数据库所在目录及数据库名
    private static String user = "sa";    // 数据库用户名
    private static String password = "sa";    // 数据库密码


    public static void main(String[] args) throws Exception {


        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
        driverManagerDataSource.setDriverClassName(driver);
        driverManagerDataSource.setUrl(url);
        driverManagerDataSource.setPassword(password);
        driverManagerDataSource.setUsername(user);

        JdbcTemplate jdbcTemplate = new JdbcTemplate(driverManagerDataSource);

        jdbcTemplate.execute("create table if not exists student(id int)");
        jdbcTemplate.execute("insert into student values(1)");
        List list = jdbcTemplate.queryForList("select * from student");
        for (Object o : list) {
            System.out.println(o);
        }
        //driverManagerDataSource.getConnection().close();
        Thread.sleep(60000);

    }
}
